﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Ext.Net;

public partial class CRM_Store_ERP_StockQuery : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ViewState_OrderSre = "CargoName asc";
            BindCenterStore(Store_Rome, Request.QueryString["tabid"]);
            gridPanel_listdata.Reload();
        }
    }


    string _QueryString;
    private string GetQryString()
    {
        string result = " 1=1 ";
        if (!string.IsNullOrEmpty(extcomb_STOREROOM_ID.SelectedItem.Text))
            result += " and StoreRoomId='" + extcomb_STOREROOM_ID.SelectedItem.Value + "' ";

        if (exttxtf_CargoName.Text.Trim() != "")
            result += " and CargoName like'%" + FilterSpecChar(exttxtf_CargoName.Text.Trim()) + "%'";
        if (exttxtf_Spec.Text.Trim() != "")
            result += " and Spec like'%" + FilterSpecChar(exttxtf_Spec.Text.Trim()) + "%'";
        if (exttxtf_Version.Text.Trim() != "")
            result += " and Version like'%" + FilterSpecChar(exttxtf_Version.Text.Trim()) + "%'";
        if (exttxtf_ProduceName.Text.Trim() != "")
            result += " and ProduceName like'%" + FilterSpecChar(exttxtf_ProduceName.Text.Trim()) + "%'";
        if (exttxtf_Area.Text.Trim() != "")
            result += " and Area like'%" + FilterSpecChar(exttxtf_Area.Text.Trim()) + "%'";
        if (exttxtf_CargoCode.Text.Trim() != "")
            result += " and CargoCode like'%" + FilterSpecChar(exttxtf_CargoCode.Text.Trim()) + "%'";

        return result;
    }

    protected void MyData_Refresh(object sender, StoreRefreshDataEventArgs e)
    {
        _QueryString = GetQryString();
        int count = 0;
        if (extRadio_D.Checked)
            count = CRMMis.BLL.ERP_StockInfo.GetRecorderCount(_QueryString);
        else
            count = CRMMis.BLL.ERP_StockInfo.GetList(_QueryString).Tables[0].Rows.Count;
        BindGridPSData(e, ViewState_OrderSre, PagingToolbar1, Store1, count);
    }

    public override DataTable GetPSData(int PageSize, int CurPage, string OrderStr)
    {
        ViewState_OrderSre = OrderStr;
        DataTable dt = null;
        if (extRadio_D.Checked)
            dt = CRMMis.BLL.ERP_StockInfo.GetPageList(PageSize, CurPage, _QueryString, OrderStr).Tables[0];
        else
            dt = CRMMis.BLL.ERP_StockInfo.GetStockList(PageSize, CurPage, _QueryString, OrderStr).Tables[0];
        return dt;
    }

    protected void OnRadioGroup_Change(object sender, DirectEventArgs e)
    {
        //gridPanel_listdata.ColumnModel.SetHidden(9, !extRadio_D.Checked);
        gridPanel_listdata.ColumnModel.SetHidden(8, !extRadio_D.Checked);
    }
}